package com.admin.testproject.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * author 吴昶
 * date 2019/5/9
 * 标注
 */
public class BaseViewHolder extends RecyclerView.ViewHolder{
    private SparseArray<View> mviews;
    private View mContentView;
    private BaseViewHolder(@NonNull View itemView) {
        super(itemView);
        mContentView=itemView;
        mviews=new SparseArray<View>();
    }

    static BaseViewHolder getHolder(ViewGroup parent, int layoutId){
        View view= LayoutInflater.from(parent.getContext()).inflate(layoutId,parent,false);
        return new BaseViewHolder(view);
    }

    public <T extends View> T getView(int viewId){
        View view=mviews.get(viewId);
        if(view==null){
            view=mContentView.findViewById(viewId);
            mviews.put(viewId,view);
        }
        return (T)view;
    }
}